package com.example.administrator.yuejian_2.adapter;

import android.app.ProgressDialog;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.bean.ClubVideoBean;
import com.example.administrator.yuejian_2.viewholder.ClubVideoViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/8.
 */

public class ClubVideoAdapter extends RecyclerView.Adapter {
    private List<ClubVideoBean> video = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;
    private String path="";

    public ClubVideoAdapter(Context context, List<ClubVideoBean> video){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.video.addAll(video);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_clubvideo,parent,false);
        ClubVideoViewHolder holder = new ClubVideoViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ClubVideoViewHolder videoholder = (ClubVideoViewHolder) holder;
        ClubVideoBean videolist = video.get(position);
        videoholder.video_name.setText(videolist.getVideo_name());
        String address = videolist.getAddress();
        path = "http://10.0.2.2/YueJian16/Public/video/"+ address ;//获取视频全路径
        Uri uri = Uri.parse(path);
        videoholder.video.setMediaController(new MediaController(context));//媒体播放控制工具
        videoholder.video.setVideoURI(uri);//设置视频路径
        videoholder.video.requestFocus();// 让VideoView获取焦点
        //videoholder.video.start();//开始播放

    }
    @Override
    public int getItemCount() {
        return video.size();
    }


}
